﻿<UserControl x:Class="Songhay.Silverlight.BiggestBox.IndexPart.Views.UserControls.DataGridRowDetails"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:dftoolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:itrig="clr-namespace:Songhay.InteractionTriggers;assembly=Songhay.Silverlight"
    xmlns:m="clr-namespace:Songhay.Silverlight.BiggestBox.IndexPart.ViewModels"
    xmlns:valuc="clr-namespace:Songhay.ValueConverters;assembly=Songhay.Silverlight"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    Tag="DataGrid Row Detail Sample"
    Width="512" Height="400">
    <UserControl.Resources>
        <m:MasterDetailViewModel x:Key="MasterDetailViewModelDatasource" d:IsDataSource="True" />
        <valuc:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <valuc:BooleanToDataGridRowDetailsVisibilityModeConverter x:Key="BooleanToDataGridRowDetailsVisibilityModeConverter" />
        <Style TargetType="ToggleButton">
            <Setter Property="Cursor" Value="Hand" />
        </Style>
        <DataTemplate x:Key="GridCellTemplate">
            <ToggleButton x:Name="GridRowToggle"
                IsChecked="{Binding IsDetailVisible, Mode=OneWay, Source={StaticResource MasterDetailViewModelDatasource}}"
                Visibility="{Binding Path=HasNestedItems, Converter={StaticResource BooleanToVisibilityConverter}}"
                Loaded="GridRowToggle_Loaded"
                Width="32" Height="32">
                <TextBlock x:Name="GridRowToggleText"
                    FontSize="18" FontWeight="Bold"
                    Foreground="DarkBlue"
                    Text="{Binding ToggleDisplayText, Mode=OneWay, Source={StaticResource MasterDetailViewModelDatasource}}"
                    />
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <itrig:DataGridToggleRowAction />
                    </i:EventTrigger>
                    <ei:DataTrigger
                        Binding="{Binding IsChecked, ElementName=GridRowToggle, Mode=TwoWay}"
                        Value="False">
                        <ei:ChangePropertyAction
                            Duration="0"
                            PropertyName="Text"
                            TargetName="GridRowToggleText"
                            Value="+" />
                    </ei:DataTrigger>
                    <ei:DataTrigger
                        Binding="{Binding IsChecked, ElementName=GridRowToggle, Mode=TwoWay}"
                        Value="True">
                        <ei:ChangePropertyAction
                            Duration="0"
                            PropertyName="Text"
                            TargetName="GridRowToggleText"
                            Value="-" />
                    </ei:DataTrigger>
                </i:Interaction.Triggers>
            </ToggleButton>
        </DataTemplate>
        <DataTemplate x:Key="RowDetailsTemplate">
            <StackPanel
                Background="BlanchedAlmond"
                Orientation="Horizontal"
                Visibility="{Binding Path=HasNestedItems, Converter={StaticResource BooleanToVisibilityConverter}}">
                <TextBlock
                    FontSize="18"
                    Text="Row Detail!"
                    />
                <data:DataGrid
                    ItemsSource="{Binding Path=NestedDataItems}"
                    />
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>
    <ScrollViewer>
        <StackPanel ScrollViewer.VerticalScrollBarVisibility="Auto"
            DataContext="{StaticResource MasterDetailViewModelDatasource}">
            <ToggleButton
                Command="{Binding ToggleDetailCommand}"
                Content="Toggle DataGrid Row Details"
                />
            <data:DataGrid
                x:Name="DataGridOne"
                ItemsSource="{Binding DataItems, Mode=OneWay}"
                IsReadOnly="True"
                RowDetailsTemplate="{StaticResource RowDetailsTemplate}"
                RowDetailsVisibilityMode="{Binding Path=IsDetailVisible, Converter={StaticResource BooleanToDataGridRowDetailsVisibilityModeConverter}}">
                <data:DataGrid.Columns>
                    <data:DataGridTemplateColumn
                        CellTemplate="{StaticResource GridCellTemplate}"
                        />
                </data:DataGrid.Columns>
            </data:DataGrid>
        </StackPanel>
    </ScrollViewer>
</UserControl>
